
@extends('layout.layer')

@section('layout.content') 
<div class="row">
  <div class="col-xs-12">
    <form class="form-horizontal" id="permission-update" autocomplete="off">
      <input type="hidden" name="_method" value="put" />
      {{ csrf_field() }}
      <div class="form-group">
          <label class="col-sm-4 control-label" for="parent"> <b><span class="red">*</span> 权限名：</b> </label>
          <div class="col-sm-6">
            <div class="radio">
              @foreach($parents as $parent)
              <label class="inline no-padding-left radio-label">
                <input name="parent" type="checkbox" value="{{$parent->id}}" class="ace ace-checkbox-2 input-lg" {{$permission->parent()->id == $parent->id?'checked':'' }} data-control="{{$parent->controller}}">
                <span class="lbl"> {{$parent->title}}</span>
              </label>
              @endforeach
            </div>            
          </div>
      </div>    
      <div class="form-group">
          <label class="col-sm-4 control-label" for="title"> <b><span class="red">*</span> 控制名：</b> </label>
          <div class="col-sm-6">
              <input type="text" value="{{$permission->title}}" class="form-control" id="title" name="title" placeholder="控制名" />
          </div>        
      </div>
      <div class="form-group">
          <label class="col-sm-4 control-label" for="action"> <b><span class="red">*</span> 模块：</b></label>
          <div class="col-sm-6">
              <input type="text" value="{{$permission->action}}" class="form-control" id="action" name="action" placeholder="模块" />
          </div>        
      </div>
      <div class="form-group">
          <label class="col-sm-4 control-label b" for="subtitle"> 显示名称：</label>
          <div class="col-sm-6">
            <input type="text" value="{{$permission->subtitle}}" class="form-control" id="subtitle" name="subtitle" placeholder="显示名称" />
          </div>        
      </div>
      <div class="form-group">
          <label class="col-sm-4 control-label b" for="order"> 排序：</label>
          <div class="col-sm-6">
              <input type="text" value="{{$permission->order}}" class="form-control" id="order" name="order" placeholder="排序" />
          </div>        
      </div>
    
      <hr />
      <div class="form-group">
        <div class="col-sm-4 center">
            <button type="button" class="btn btn-primary submit">
              <i class="ace-icon fa fa-check"></i>
              <span class="">确定</span>
            </button>
            <button type="button" class="btn btn-grey cancel" style="margin-left: 10px;">
              <i class="ace-icon fa fa-close"></i>
              <span class="">取消</span>
            </button>
        </div>
      </div>
      
    </form>
  </div>
</div>

@stop

@section('javascript')
<script type="text/javascript">
  $(function() {

    $('.submit').on('click', function() {

      var uri = '{{route('system.permission.update', $permission->id)}}';  

      $.post(uri, {
        '_token':$("input[name='_token']").attr('value'),
        '_method': $("input[name='_method']").attr('value'),
        'parent': $("input[name='parent']:checked").val(),
        'control': $("input[name='parent']:checked").data('control'),
        'title': $("input[name='title']").val(),
        'subtitle': $("input[name='subtitle']").val(),
        'action': $("input[name='action']").val(),
        'order': $("input[name='order']").val(),
        'is_submit': true
      }, function(data) {
        layer.msg(data.message, {time: 2000,shift: -1}, function () {
          if (data.status === true) {
            parent.location.reload();
            parent.layer.close(parent.layer.index);
          }
        });
      },'json').error(function(data){
        layer.msg(data.responseJSON.message);
      }); 
      
    });

    $('.cancel').on('click', function() {
      parent.layer.closeAll();
    });


    $("input:checkbox[name='parent']").on('click', function (e) {
        $("input:checkbox[name='parent']").not(this).attr("checked", false);
    });
   

  });
</script>
@stop